import type {
  ConsultOrderItem,
  ConsultOrderListParams,
  ConsultOrderPage,
  ConsultOrderPreData,
  ConsultOrderPreParams,
  DoctorPage,
  FollowType,
  Image,
  KnowledgePage,
  KnowledgeParams,
  PageParams,
  PartialConsult,
  TopDep
} from '@/types/consult'
import type { PatientItem } from '@/types/user'
import request from '@/utils/request'

// 获取首页文章列表
export const getKownledgeList = (params: KnowledgeParams) =>
  request<KnowledgePage>('/patient/home/knowledge', 'GET', params)

// 获取关注医生列表数据
export const getDoctorList = (params: PageParams) =>
  request<DoctorPage>('/home/page/doc', 'GET', params)

// 关注/取消关注医生
export const followDoctor = (type: FollowType, id: string) =>
  request('/like', 'POST', {
    type,
    id
  })

// 获取科室数据
export const getAllDep = () => request<TopDep[]>('/dep/all', 'GET')

// 图片上传
export const uploadFile = (file: File) => {
  const fd = new FormData()
  fd.append('file', file)
  return request<Image>('/upload', 'POST', fd)
}

// 获取预支付信息
export const getPayInfo = (params: ConsultOrderPreParams) =>
  request<ConsultOrderPreData>('/patient/consult/order/pre', 'GET', params)

// 获取患者信息
export const getPatientInfo = (id: string) => request<PatientItem>(`/patient/info/${id}`, 'GET')

// 生成订单
export const createOrder = (params: PartialConsult) =>
  request<{ id: string }>('/patient/consult/order', 'POST', params)

// 支付接口
export const pay = (params: { paymentMethod: 0 | 1; orderId: string; payCallback: string }) =>
  request<{ payUrl: string }>('/patient/consult/pay', 'POST', params)

// 获取订单详情信息
export const getCousultOrderDetail = (orderId: string) =>
  request<ConsultOrderItem>('/patient/consult/order/detail', 'GET', {
    orderId
  })

// 查看处方
export const previewPre = (id: string) =>
  request<{ url: string }>(`/patient/consult/prescription/${id}`, 'GET')

// 获取问诊订单
export const getConsultList = (params: ConsultOrderListParams) =>
  request<ConsultOrderPage>('/patient/consult/order/list', 'GET', params)

// 取消订单
export const cancelOrder = (id: string) => request(`/patient/order/cancel/${id}`, 'PUT')

// 删除订单
export const deleteOrder = (id: string) => request(`/patient/order/${id}`, 'DELETE')
